import React from 'react';
import { useNavigate } from 'react-router-dom';
import cookie from 'react-cookies'

const AuthRouter = (props) => {
    let navigate = useNavigate();
    const AuthLogin = () => {
        React.useEffect(() => {
            const LoginUser = cookie.load('LoginUser') ? cookie.load('LoginUser') : {}
            if (JSON.stringify(LoginUser) === "{}") { 
                navigate('/business/base/login')
            }
        })
        return false;
    }
    return (
        <>
            {props.auth && <AuthLogin />}
            {props.component}
        </>
    )
}

export default AuthRouter;